const { ipcMain } = require("electron");
const { createWin } = require("./share");
const path = require("path");

const createCamviewWin = () => {
    const CamviewWin = createWin({
        width: 320,
        height: 184,
        webPreferences: {
            nodeIntegration: true, // 允许预加载js文件使用require模块
            preload: path.join(__dirname, "../src/view/camera/preload.js"),
        },
    }, "./src/view/camera/index.html");
    return CamviewWin;
};
const createIpcCam = () => {
    let camvWin
    ipcMain.on("open-cameraview", () => {
        camvWin = createCamviewWin();

        camvWin.setAlwaysOnTop(true);

        // 监听窗口关闭
        camvWin.on('closed', () => {
            camvWin = null
        })
    });

    ipcMain.on("close-cameraview", () => {
        camvWin.close();
    });
}

module.exports = {
    createIpcCam
}